package com.zbkj.crmeb.merchant.admin.controller;

import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.statistics.response.HomeRateResponse;
import com.zbkj.crmeb.statistics.service.HomeService;
import com.zbkj.crmeb.statistics.response.CustomerManagementResponse;
import com.zbkj.crmeb.statistics.response.OrderTodayResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;
import java.util.Map;


/**
 * 统计 -- 主页 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/mer/statistics/home")
@Api(tags = "统计 -- 主页")
public class MerHomeController extends AdminBaseController {

    @Autowired
    private HomeService homeService;

    /**
     * 销售额
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "销售额")
    @RequestMapping(value = "/sales", method = RequestMethod.GET)
    public CommonResult<HomeRateResponse> sales(HttpServletRequest request){
        return CommonResult.success(homeService.sales(Collections.singletonList(getMerId(request))));
    }

    /**
     * 订单量
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "订单量")
    @RequestMapping(value = "/order", method = RequestMethod.GET)
    public CommonResult<HomeRateResponse> order(HttpServletRequest request){
        return CommonResult.success(homeService.order(Collections.singletonList(getMerId(request))));
    }


    /**
     * 新增用户
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "新增用户")
    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public CommonResult<HomeRateResponse> user(HttpServletRequest request){
        return CommonResult.success(homeService.user(Collections.singletonList(getMerId(request))));
    }

    /**
     * 用户访问量
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "用户访问量")
    @RequestMapping(value = "/views", method = RequestMethod.GET)
    public CommonResult<HomeRateResponse> views(HttpServletRequest request){
        return CommonResult.success(homeService.views(Collections.singletonList(getMerId(request))));
    }

    /**
     * 用户曲线图
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "用户曲线图")
    @RequestMapping(value = "/chart/user", method = RequestMethod.GET)
    public CommonResult<Map<Object, Object>> chartUser(HttpServletRequest request){
        return CommonResult.success(homeService.chartUser(Collections.singletonList(getMerId(request))));
    }

    /**
     * 用户购买统计
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "用户购买统计")
    @RequestMapping(value = "/chart/user/buy", method = RequestMethod.GET)
    public CommonResult<Map<String, Integer>> chartUserBuy(HttpServletRequest request){
        return CommonResult.success(homeService.chartUserBuy(Collections.singletonList(getMerId(request))));
    }

    /**
     * 30天订单量趋势
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "30天订单量趋势")
    @RequestMapping(value = "/chart/order", method = RequestMethod.GET)
    public CommonResult<Map<String, Object>> chartOrder(HttpServletRequest request){
        return CommonResult.success(homeService.chartOrder(Collections.singletonList(getMerId(request))));
    }

    /**
     * 周订单量趋势
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "周订单量趋势")
    @RequestMapping(value = "/chart/order/week", method = RequestMethod.GET)
    public CommonResult<Map<String, Object>> chartOrderInWeek(HttpServletRequest request){
        return CommonResult.success(homeService.chartOrderInWeek(Collections.singletonList(getMerId(request))));
    }

    /**
     * 月订单量趋势
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "月订单量趋势")
    @RequestMapping(value = "/chart/order/month", method = RequestMethod.GET)
    public CommonResult<Map<String, Object>> chartOrderInMonth(HttpServletRequest request){
        return CommonResult.success(homeService.chartOrderInMonth(Collections.singletonList(getMerId(request))));
    }

    /**
     * 年订单量趋势
     * @author Mr.Zhang
     * @since 2020-05-16
     */
    @ApiOperation(value = "年订单量趋势")
    @RequestMapping(value = "/chart/order/year", method = RequestMethod.GET)
    public CommonResult<Map<String, Object>> chartOrderInYear(HttpServletRequest request){
        return CommonResult.success(homeService.chartOrderInYear(Collections.singletonList(getMerId(request))));
    }

    /**
     * 商家小程序今日数据
     */
    @ApiOperation(value = "商家小程序今日数据")
    @GetMapping(value = "/order/today")
    public CommonResult<List<OrderTodayResponse>> orderToday(HttpServletRequest request){
        return CommonResult.success(homeService.orderToday(getMerId(request)));
    }

    /**
     * 商家小程序客户管理
     */
    @ApiOperation(value = "商家小程序客户管理")
    @GetMapping(value = "/customer/management")
    public CommonResult<CustomerManagementResponse> customerManagement(HttpServletRequest request){
        return CommonResult.success(homeService.customerManagement(getMerId(request)));
    }

}



